/*
 * main.c
 *
 *  Created on: Aug 8, 2013
 *      Author: lxzhu
 */
#include <GL/gl.h>
#include <GL/glu.h>
#include <GL/glut.h>
//定义全局的顶点数组
GLfloat vertices[] = { -1.0, -1.0, 1.0, -1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0,
		-1.0, 1.0, -1.0, -1.0, -1.0, -1.0, 1.0, -1.0, 1.0, 1.0, -1.0, 1.0, -1.0,
		-1.0 };

//定义全局的颜色数组
GLfloat colors[] = { 1.0, 0.0, 0.0, 0.0, 1.0, 1.0, 1.0, 1.0, 0.0, 0.0, 1.0, 0.0,
		0.0, 0.0, 1.0, 1.0, 0.0, 1.0 };
GLubyte cubeVertexIndices[]= {2,1,0,3,2,3,7,6,3,0,4,7,6,5,1,2,4,5,6,7,4,0,1,5};
void init();
void draw();

int main(int argc, char** argv) {
	glutInit(&argc, argv);
	glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB);
	glutInitWindowSize(800, 600);
	glutCreateWindow("VerticeArray");
	glutDisplayFunc(draw);
	init();
	glutMainLoop();
	return 0;
}

void init() {
	glMatrixMode(GL_PROJECTION);
	gluLookAt(1, 1, 1, 0, 0, 0, 0, 0, 1);
	glMatrixMode(GL_MODELVIEW);
	glEnableClientState(GL_VERTEX_ARRAY);
	glEnableClientState(GL_COLOR_ARRAY);
	glVertexPointer(3,GL_FLOAT,0,vertices);
	glColorPointer(3,GL_FLOAT,0,colors);
}
void draw() {
	glClear(GL_COLOR_BUFFER_BIT);
	glDrawElements(GL_QUADS,24,GL_UNSIGNED_BYTE,cubeVertexIndices);
	//glDrawArrays(GL_QUADS,0,6);
    glutSwapBuffers();
}

